package com.plateno.exception;

import org.codehaus.jackson.node.ObjectNode;

import com.plateno.bean.model.Config;
import com.plateno.util.JsonUtil;



public class PlatenoException extends RuntimeException {

	private static final long serialVersionUID = 3022481503667660306L;
	

	private int errorCode;
	private String errorMessage;
	private Object result;

	public PlatenoException(int errorCode,String message){
		this.errorCode = errorCode;
		this.errorMessage = message;
	}

    public PlatenoException(Config.MsgCode msgCode){
        this.errorCode = msgCode.getMsgCode();
        this.errorMessage = msgCode.getMessage();
    }

	public int getErrorCode() {
		return errorCode;
	}

	public String getErrorMessage() {
		return errorMessage;
	}
	
	public Object getResult() {
		return result;
	}

	@Override
	public String getMessage() {
		ObjectNode node = JsonUtil.createObjectNode();
		node.put("msgCode", errorCode);
		node.put("message", errorMessage);
		node.putPOJO("result", result);
		return node.toString();
	}

	/**
	 * 避免获取方法栈快照信息
	 */
	@Override
	public Throwable fillInStackTrace() {
		return this;
	}
}
